package com.cs307.redcross.client;

import java.io.Serializable;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class EventsSubheader extends Subheader implements Serializable {
	private static final long serialVersionUID = 4223721994412995286L;
	protected ToggleButton selectedButton;
	
	public EventsSubheader() {
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		initWidget(horizontalPanel);
		horizontalPanel.setSize("239px", "15px");
		
		FlexTable flexTable = new FlexTable();
		horizontalPanel.add(flexTable);
		flexTable.setWidth("318px");
		
		ToggleButton btnEdit = new ToggleButton("Edit");
		btnEdit.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// show the new content in ContentPanel
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(btnEdit);
		btnEdit.setSize("53px", "18px");
		
		ToggleButton btnView = new ToggleButton("View");
		btnView.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// show the new content in ContentPanel
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(btnView);
		btnView.setSize("53px", "18px");
		
		ToggleButton btnCreate = new ToggleButton("Create");
		btnCreate.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// show the new content in ContentPanel
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(btnCreate);
		btnCreate.setSize("53px", "18px");
		
		// set view to be the default view loaded
		btnView.setDown(true);
		selectedButton = btnView;
	}

}
